/*
 * Copyright (c) 2016, www.zm0618.com All Rights Reserved..
 */

package com.ibetter.mr.grade.medic.voteup;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


/**
 * Created by zhaojun on 2016/12/10.
 */
public class GradeUserVoteMedicMapper extends Mapper<LongWritable,Text,Text,DoubleWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        if (value!=null){//点赞0.3分
            String valStr=value.toString();
            if(StringUtils.isNotBlank(valStr)){
                String[] voteUpField = valStr.split(",");
                if (ArrayUtils.isNotEmpty(voteUpField)){
                    String userIdStr=voteUpField[1];
                    String medicIdStr=voteUpField[2];
                   /* LongWritable userIdLong=new LongWritable(Long.parseLong(StringUtils.trim(userIdStr)));
                    LongWritable medicIdLong=new LongWritable(Long.parseLong(StringUtils.trim(medicIdStr)));*/
                    context.write(new Text(StringUtils.join(new String[]{StringUtils.trim(userIdStr),StringUtils.trim(medicIdStr)},",")),new DoubleWritable(0.3));
                }
            }
        }
    }
}
